package org.example.ch04;

public class Fibonacc {

    public static void main(String[] args) {
        int[] arr = new int[6];
        int result = solution2(5,arr);
//        int result = solution1(5);
        System.out.println(result);
    }

    public static int solution1(int n){
        if(n<=1){
            return n;
        }
        return solution1(n-1) + solution1(n-2);
    }

    public static int solution2(int n,int[] array){
        if(n<=1){
            return n;
        }
        if(array[n] == 0){
            return solution1(n-1) + solution1(n-2);
        }

        return array[n];
    }
}
